#!/user/bin/evn Python3 
# -*- coding:utf-8 -*-
# project:PythonForWork
# Decorator.py
# 相关触发器
# author:ZhaoHeXin
# creation time:2019/11/29--13:55

import time
import hashlib


def timer(fun):
    """
    计时器函数
    :param fun:需要计时的函数
    :return:返回消耗时间
    """

    def wrapper(*args, **kwargs):
        start_time = time.time()
        fun(*args, **kwargs)
        end_time = time.time()
        print(f'============该操作耗时{end_time - start_time}============')

    return wrapper


def Md5ForStr(func):
    """
    只针对于函数返回的字符串进行md5加密处理

    @param func:函数-函数必须返回为字符串
    @return:md5加密好的密码
    """

    def wrapper(*args, **kwargs):
        str = func(*args, **kwargs)
        # 进行MD5码加密
        m = hashlib.md5()
        m.update(str.encode("utf8"))
        return m.hexdigest()

    return wrapper


if __name__ == '__main__':
    @Md5ForStr
    def get_str(a):
        return a


    a = get_str("asdasdasdas")
    print(a)
